File
object to exist without a file?
File
object?
File
Constructors
A File
object is constructed by a program and used
to manipulate a disk file and to get information about it.
When the program finishes, the File
object is no more,
but the file remains on disk (unless the program deliberately deleted it).
Here is one of the constructors for File
:
// Construct a File object for a file // with name pathName. File( String pathName )
The path name of a file is a chain of directory names followed by a file name. The directory names are separated by a special character. The syntax for directory names, separators, and file names depends on the operating system.
Here is a path name for a MS Windows file:
C:\MyFiles\Programs\someFile.txt
The directory separator character (for MS Windows) is "\". The last part of the path name, following the last separator, is the file name. Here is a Unix path name:
/usr/frodo/Programs/someFile.txt
Path names are relative or absolute.
An absolute path name gives the complete chain of
directories from the root directory to the file.
A relative path name starts with any directory
in the chain and continues to the file.
Both relative and absolute path names may be
used with the File
constructor.
Is the following a correct use of a constructor?
File progFile = new File( "C:\MyFiles\Programs\Examples\someFile.txt" );